<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>数组操作</title>
  </head>
  <body>
  <script type="text/javascript">
    var arr=[3,1,2,2,1,3,1];
    var sum=[];
    var res=[];
    var count=0;
    var temp;
    for(var i=0;i<arr.length;i++){
      if(res.indexOf(arr[i])==-1){
        res.push(arr[i]);
      }
    }
    for(var i=0;i<res.length;i++){
      for(var j=0;j<arr.length;j++){
        if(arr[j]==res[i]){
          count++;
        }
      }
      sum.push(count);
      count=0;
    }
    console.log(res);//[3,1,2]
    for(var i=0;i<res.length;i++){
      var str=(sum[i]%2==0)?"偶数":"奇数";
      console.log(res[i]+"出现了"+sum[i]+"次");
      console.log(res[i]+"出现了"+str+"次");
    }
  </script>
  </body>
</html>
